﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SGC.BE;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace SGC.DL.DL_CcuActualizarCheckListProcedimiento
{
    public class DL_CcuActualizarCheckListProcedimiento
    {

        static string Str_ConSql = ConfigurationManager.ConnectionStrings["Cn_Sql"].ToString();
        static SqlConnection sCn_Ap = new SqlConnection(Str_ConSql);

        public static List<BE_Checklist> obtenerCheckList_DL(String BuscarCadena)
        {
            BE_Checklist objChecklist = null;
            List<BE_Checklist> lstChecks = new List<BE_Checklist>();
            using (SqlCommand sCmd_Sp = new SqlCommand())
            {
                sCmd_Sp.CommandType = CommandType.StoredProcedure;
                sCmd_Sp.CommandText = "BUSCAR_CHECKLIST";
                sCmd_Sp.Connection = sCn_Ap;
                sCn_Ap.Open();
                SqlDataReader sDar_Datos;

                #region Parámetros

                SqlParameter oParm1 = new SqlParameter("@CADENA", SqlDbType.VarChar, 100);
                oParm1.Direction = ParameterDirection.Input;
                sCmd_Sp.Parameters.Add(oParm1);
                sCmd_Sp.Parameters["@CADENA"].Value = BuscarCadena;

                #endregion
                sDar_Datos = sCmd_Sp.ExecuteReader();
                while (sDar_Datos.Read())
                {
                    objChecklist = new BE_Checklist();
                    objChecklist.IDCHECKLIST = sDar_Datos["IDCHECKLIST"].ToString();
                    objChecklist.DESCRIPCION = sDar_Datos["DESCRIPCION"].ToString();
                    lstChecks.Add(objChecklist);
                }
                sCn_Ap.Close();
            }
            return lstChecks;
        }

        public static int actualizarChecklistProcedimiento_DL(BE_CheckListProcedimiento objCheckProc, Boolean Accion, ref String strError)
        {
            strError = "";
            int Int_Valret = 0;
            using (SqlCommand sCmd_Sp = new SqlCommand())
            {
                sCmd_Sp.CommandType = CommandType.StoredProcedure;
                sCmd_Sp.CommandText = "UPDATE_CHECKLISTPROCEDIMIENTO";
                sCmd_Sp.Connection = sCn_Ap;
                sCn_Ap.Open();

                #region Parámetros

                SqlParameter oParm1 = new SqlParameter("@CHECK", SqlDbType.Char, 10);
                oParm1.Direction = ParameterDirection.Input;
                sCmd_Sp.Parameters.Add(oParm1);
                sCmd_Sp.Parameters["@CHECK"].Value = objCheckProc.CODIGO_CHECK;

                oParm1 = new SqlParameter("@PROCEDIMIENTO", SqlDbType.Char, 10);
                oParm1.Direction = ParameterDirection.Input;
                sCmd_Sp.Parameters.Add(oParm1);
                sCmd_Sp.Parameters["@PROCEDIMIENTO"].Value = objCheckProc.CODIGO_PROC;

                oParm1 = new SqlParameter("@VALOR", SqlDbType.Char, 30);
                oParm1.Direction = ParameterDirection.Input;
                sCmd_Sp.Parameters.Add(oParm1);
                sCmd_Sp.Parameters["@VALOR"].Value = objCheckProc.VALOR_ESPERADO;

                oParm1 = new SqlParameter("@ACC", SqlDbType.Bit);
                oParm1.Direction = ParameterDirection.Input;
                sCmd_Sp.Parameters.Add(oParm1);
                sCmd_Sp.Parameters["@ACC"].Value = Accion;

                #endregion

                try
                {
                    Int_Valret = sCmd_Sp.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    strError = ex.Message;
                }
                sCn_Ap.Close();
                return Int_Valret;
            }
        }
    }
}
